package com.mallotec.android.timenote.ui.activity;

import android.os.Bundle;
import android.view.MenuItem;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import androidx.databinding.DataBindingUtil;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.fragment.NavHostFragment;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.mallotec.android.timenote.R;
import com.mallotec.android.timenote.databinding.ActivityMainBinding;
import com.mallotec.android.timenote.ui.common.BaseActivity;

import java.util.Objects;

public class MainActivity extends BaseActivity<ActivityMainBinding> {

     // private AppBarConfiguration appBarConfiguration;
     private NavController navController;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void onInitView(Bundle savedInstanceState) {
        /*if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.nav_main_fragment, HomeFragment.newInstance())
                    .commitNow();
        }*/

        BottomNavigationView bottomNavigationView = binding.bnvView;
        NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.nav_main_fragment);
        // this.navController = navHostFragment.findNavController(this, R.id.nav_main_fragment);
        this.navController = Objects.requireNonNull(navHostFragment).getNavController();
        // this.appBarConfiguration = new AppBarConfiguration.Builder(navController.getGraph()).build();
        /*this.appBarConfiguration = new AppBarConfiguration.Builder(
                R.id.HistoryFragment, R.id.GoalFragment
        ).build();*/

        // Set up ActionBar
        // Toolbar toolbar = binding.toolbar;
        // setSupportActionBar(toolbar);
        // NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);

        // Set up navigation menu
        NavigationUI.setupWithNavController(bottomNavigationView, navController);
    }

    @Override
    protected void onInit(Bundle savedInstanceState) {
    }

    /*@Override
    public boolean onSupportNavigateUp() {
         NavController navController = Navigation.findNavController(this, R.id.nav_main_fragment);
        return NavigationUI.navigateUp(navController, appBarConfiguration)
                || super.onSupportNavigateUp();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
         NavController navController = Navigation.findNavController(this, R.id.nav_main_fragment);
        return NavigationUI.onNavDestinationSelected(item, navController)
                || super.onOptionsItemSelected(item);
    }*/
}